import wx
class ListbookExample(wx.Frame):
    def __init__(self, parent, title):
        super(ListbookExample, self).__init__(parent,
                                              title=title,
                                              size=(400, 300))

        self.listbook = wx.Listbook(self, style=wx.LB_DEFAULT)

        self.page1 = wx.Panel(self.listbook)
        wx.StaticText(self.page1, label="这是第一个页面", pos=(10, 10))
        button1 = wx.Button(self.page1, label="按钮1",
                            pos=(10, 50))
        button1.Bind(wx.EVT_BUTTON, self.on_button1)

        self.page2 = wx.Panel(self.listbook)
        wx.StaticText(self.page2, label="这是第二个页面", pos=(10, 10))
        button2 = wx.Button(self.page2, label="按钮2", pos=(10, 50))
        button2.Bind(wx.EVT_BUTTON, self.on_button2)

        # 将页面添加到 Listbook
        self.listbook.AddPage(self.page1, "页面 1")
        self.listbook.AddPage(self.page2, "页面 2")

        self.listbook.SetSize(self.GetClientSize())

        # 绑定事件处理器
        self.listbook.Bind(wx.EVT_LISTBOOK_PAGE_CHANGED,
                           self.on_page_changed)

    def on_button1(self, event):
        wx.MessageBox("按钮1被点击了", "信息")

    def on_button2(self, event):
        wx.MessageBox("按钮2被点击了", "信息")

    def on_page_changed(self, event):
        selection = self.listbook.GetSelection()
        wx.MessageBox(f"当前选中的页面是：{selection + 1}",
                      "页面更改")

app = wx.App(False)
# 创建主窗口
frame = ListbookExample(None, 'wx.Listbook 示例')
# 显示主窗口
frame.Show()
# 进入应用程序主循环
app.MainLoop()